package com.csun.cmny.provider.service.impl;

import com.csun.cmny.core.support.BaseService;
import com.csun.cmny.provider.dao.DmcCsunVersionSetDeviceMapper;
import com.csun.cmny.provider.model.domain.DmcCsunVersionSetDevice;
import com.csun.cmny.provider.model.domain.DmcDevice;
import com.csun.cmny.provider.service.DmcCsunVersionSetDeviceService;
import com.csun.cmny.util.PublicUtil;
import com.google.common.collect.Lists;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2020/4/3 10:29
 * @Description: the class dmc csun version set device service impl
 */
@Service
@Transactional
public class DmcCsunVersionSetDeviceServiceImpl extends BaseService<DmcCsunVersionSetDevice> implements DmcCsunVersionSetDeviceService {

    @Resource
    private DmcCsunVersionSetDeviceMapper dmcCsunVersionSetDeviceMapper;

    /**
     * batch update csun version set device stat
     *
     * @param versionSetId the version set id
     * @param deviceIdList the device id list
     * @param before       the before stat
     * @param stat         the stat
     *
     * @return the int.
     */
    @Override
    public Integer batchUpdateStat(Long versionSetId, List<Long> deviceIdList, Integer before, Integer stat) {

        if (PublicUtil.isEmpty(deviceIdList)) {
            return 0;
        }

        return dmcCsunVersionSetDeviceMapper.batchUpdateStat(versionSetId, deviceIdList, before, stat);
    }

    /**
     * query device id list
     *
     * @param versionSetId the version set id
     * @param stat         the stat
     *
     * @return the list.
     */
    @Override
    public List<DmcDevice> queryDeviceIdList(Long versionSetId, int stat) {

        return dmcCsunVersionSetDeviceMapper.queryDeviceIdList(versionSetId, stat);
    }

    /**
     * 批量更新设备升级状态
     *
     * @param dmcCsunVersionSetDeviceList the list of dmc csun version set device
     *
     * @return the int.
     */
    @Override
    public Integer batchUpdate(List<DmcCsunVersionSetDevice> dmcCsunVersionSetDeviceList) {

        return dmcCsunVersionSetDeviceMapper.batchUpdate(dmcCsunVersionSetDeviceList);
    }

    /**
     * update dmc csun version set device stat by task id
     *
     * @param taskId the task id
     * @param stat   the stat
     *
     * @return the int.
     */
    @Override
    public Integer updateByTaskId(String taskId, int stat) {

        return dmcCsunVersionSetDeviceMapper.updateByTaskId(taskId, stat);
    }

    /**
     * update by time and stat
     *
     * @param time   the time
     * @param before the before
     * @param after  the after
     *
     * @return the int.
     */
    @Override
    public Integer updateByTimeAndStat(String time, int before, int after) {

        return dmcCsunVersionSetDeviceMapper.updateByTimeAndStat(time, before, after);
    }
}
